package com.itheima.mapper;

import com.itheima.domain.Trip;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author ChaunceyZhang
 * @date 2022-10-16 20:17
 * @blog1 https://zephyr-cyber.github.io/
 * @blog2 https://www.yuque.com/gougougou-xwscx
 */
public interface TripMapper {
    /**
     * findAll
     *
     * @return
     */
    @Select("select * from tb_trip")
    List<Trip> findAll();

    /**
     * save
     *
     * @param trip
     */
    @Insert("insert into tb_trip(username,gender,idcard,from_address,to_address,start_time) values(#{username},#{gender},#{idCard},#{fromAddress},#{toAddress},#{startTime})")
    void save(Trip trip);

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Delete("delete from tb_trip where id = #{id}")
    Integer delete(Integer id);


    /**
     * findById
     *
     * @param id
     * @return
     */
    @Select("select * from tb_trip where id = #{id}")
    List<Trip> findById(Integer id);

    /**
     * update
     *
     * @param trip
     */
    @Update("update tb_trip  set id=#{id}, username=#{username}, gender=#{gender}, idcard=#{idCard}, from_address=#{fromAddress}," +
            "to_address=#{toAddress}, start_time=#{startTime} where id = #{id}")
    void update(Trip trip);
}
